<template>
	<view>
		<!-- 搜索 -->
		<my-search @click="searchClick"></my-search>
		<view class="scroll-view-container">
			<!-- 左侧菜单 -->
			<scroll-view class="lift-view" scroll-y="true" :style="{height:wh + 'px'}">
				<block v-for="(item,index) in CateList" :key="item.cat_id">
					<view class="lift-item" :class="index==catindex ? 'actetf' :''" @click="handoxuanz(index)">
						{{item.cat_name}}</view>
				</block>
			</scroll-view>	
			<!-- 右侧菜单 -->
			<scroll-view class="right-view" scroll-y="true" :style="{height: wh + 'px'}" scroll-top="scrollTop">
					<view class="right-item" v-for="itemm in CateList2" :key="itemm.cat_id">
						<view class="totie">*{{itemm.cat_name}}*</view>
						<view class="item-list">
							<view class="right-list" v-for="itemmm in itemm.children" :key="itemmm.cat_id" @click="gotoGoodsList(itemmm.cat_id)">
								<image :src="itemmm.cat_icon" mode="widthFix" style="width: 60px;height: 60px;"></image>
								<view class="name">{{itemmm.cat_name}}</view>
							</view>
						</view>
					</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				wh: 0,
				CateList: [],
				CateList2: [],
				catindex: 0,
				scrollTop:0
			};
		},
		onLoad() {
			//获取手机的可用高度，给分类列表动态获取高度
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight - 50
			//获取分类数据
			this.getcateList()
		},
		methods: {
			//获取分类数据
			async getcateList() {
				const { data: res } = await uni.$http.get('/categories')
				if (res.meta.status === 200) {
					this.CateList = res.message
					this.CateList2 = res.message[0].children
				}
			},
			//左侧菜单点击事件
			handoxuanz(index) {
				this.catindex = index
				this.CateList2 = this.CateList[index].children
				this.scrollTop = this.scrollTop == 0 ? 1 : 0
			},
			//点击分类商品跳转至该商品详情
			gotoGoodsList(id){
				uni.navigateTo({
					url:'/subpkg/goods_list/goods_list?id=' + id
				})
			},
			//搜索框点击事件
			searchClick(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	.scroll-view-container {
		display: flex;

		.lift-view {
			width: 120px;
			.lift-item {
				background-color: #F7F7F7;
				line-height: 60px;
				text-align: center;
				font-size: 12px;

				&.actetf {
					background-color: #FFFFFF;
					border-left: 3px solid #ffaa00;
					border-radius: 5px 0px 0px 5px;
					color: #ffaa00;
				}
			}
		}
		.right-view{
			background: #FFFFFF;
			.right-item{
				.totie{
					margin: 20rpx 0;
					font-size: 30rpx;
					font-weight: bolder;
					text-align: center;
				}
				.item-list{
					display: flex;
					flex-wrap: wrap;
					.right-list{
						width: 33.33%;
						display: flex;
						justify-content: center;
						flex-direction: column;
						align-items: center;
						margin-bottom: 20rpx;
						.name{
							font-size: 12px;
						}
					}
				}
			}
		}
	}
</style>
